﻿@{
    Layout = null;
}

<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
<link href="~/Content/jquery-easyui-1.4.2/demo.css" rel="stylesheet" />
<link href="~/Content/Styles/Manage_Order.css" rel="stylesheet" />
<script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
<script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
<script>
    $(function () {
        GetMer();//加载操作员管理的所有商户

    })

    var Mer;//商户ID
    var diplayText;//商户名称
    var EvaID;//评价信息ID
    var DishesID;//菜品ID
    var AccID;//用户ID
    var EvaStars;//评价星级

    //获取商户
    function GetMer() {
        var grid = $('#SearchMer').combogrid({
            panelWidth: 500,
            idField: 'MerID',
            textField: 'MerName',
            url: '/Order_Eva/getMer',
            method: 'post',
            pageSize: 5,
            pageList: [5],
            pagination: true,
            rownumbers: true,
            fitColumns: true,
            columns: [[
                { field: 'MerID', title: '商户ID', width: 80, align: 'center' },
                { field: 'MerName', title: '商户名称', width: 80, align: 'center' },
                { field: 'MerTxt', title: '商户介绍', width: 120, align: 'center' },
                { field: 'MerAdr', title: '商户地址', width: 80, align: 'center' },
                { field: 'MerCall', title: '商户联系电话', width: 80, align: 'center' }
            ]],
            onSelect: function (index, row) {
                diplayText = row[grid.combogrid('options').textField];
                Mer = $('#SearchMer').combogrid("getValue");//获取操作员
                //加载对应订单
                initTable(Mer);
                //控制增删查改的权限
                $.post("/Order_Eva/getPower", function (database) {
                    if (database != "") {
                        $('#btndetail').linkbutton('enable');
                        if (database.Dell == 1) {
                            $('#btndell').linkbutton('enable');
                        }
                    }
                })
            },
            onLoadSuccess: function () {
                //分页后判断下是否有选中的数据行，combogrid会依据上一次选中的值进行初始化，选中datagrid数据行和设置显示值
                if (!grid.combogrid('grid').datagrid('getSelected'))//不在当前页
                {
                    $('#SearchMer').combogrid("setValue", diplayText);
                }
            }
        });
    }
    //初始化表格 
    function initTable(Mer) {
        $('#View').datagrid({
            iconCls: 'icon-user',
            loadMsg: '数据加载中...',
            fitColumns: true,
            nowrap: true,
            autoRowHeight: true,
            striped: true,
            url: '/Order_Eva/getgrid?MerID=' + Mer,
            sortName: 'DishesID',
            sortOrder: 'asc',
            border: true,
            remoteSort: false,
            idField: 'DishesID',
            pageSize: 10,
            singleSelect: true,
            pagination: true,
            rownumbers: true,
            columns: [[
                { field: 'EvaID', title: 'EvaID', sortable: true, hidden: true },
                { field: 'DishesID', title: 'ID', sortable: true, hidden: true },
                { field: 'FormID', title: '订单号', sortable: true },
                { field: 'DishesNmae', title: '商品名称', sortable: true },
                { field: 'MerName', title: '商户名称', sortable: true },
                { field: 'AccName', title: '用户名称' },
                { field: 'EvaStars', title: '评价星级' },
                {field: 'EvaTime', title: '评价时间'},
                { field: 'EvaTxt', title: '评价内容', width: 100, sortable: true, align: 'center' },
                { field: 'MerTxt', title: '商家回复', width: 100, sortable: true, align: 'center' },
                { field: 'BZ', title: '备注', width: 100, sortable: true, align: 'center' },
            ]],
            toolbar: '#tb1',
        });
    }

    //根据商品名称、订单号、星级检索商品评价
    function SearchDishes() {
        var FormID = $('#FormID').textbox('getValue');//订单号
        var Star = $('#Star').combobox('getValue');//星级
        var DishesName = $('#SearchDishes').textbox('getValue');//商品名称
        $('#View').datagrid({
            url: '/Order_Eva/searchEva?MerID=' + Mer + "&Dishes=" + DishesName + "&FormID=" + FormID + "&Star=" + Star,
        });
    }

    //商品评价信息明细对话话框
    function DetailDialog() {
        var UpdateInfoID = $("#View").datagrid("getSelections");
        if (UpdateInfoID.length == 1) {
            $("#editDialog").dialog("open").dialog("setTitle", "商品评价明细");
            BingUpdate();
        }
        else {
            $.messager.alert("友情提示", "每次只能查看一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
        }
    }

    //给商品订单编辑界面赋值
    function BingUpdate() {
        //首先获取选中的商品订单
        var checkdata = $("#View").datagrid("getSelections")[0];
        if (checkdata != null) {
            EvaID = checkdata.EvaID;
            DishesID = checkdata.DishesID;
            AccID = checkdata.AccID;
            EvaStars = checkdata.EvaStars;
            $("#DishesNmae").textbox('setValue', checkdata.DishesNmae);
            $("#Form").textbox('setValue', checkdata.FormID);
            $("#AccName").textbox('setValue', checkdata.AccName);
            $("#EvaTime").textbox('setValue', checkdata.EvaTime);
            $("#EvaTxt").textbox('setValue', checkdata.EvaTxt)
            $("#MerTxt").textbox('setValue', checkdata.MerTxt);
            $("#BZ").textbox('setValue', checkdata.BZ);
            //动态设计星星的效果无效果
            $('#starid1').addClass('classStar');
            $('#starid2').addClass('classStar');
            $('#starid3').addClass('classStar');
            $('#starid4').addClass('classStar');
            $('#starid5').addClass('classStar');
            //有效果
            switch (checkdata.EvaStars) {
                case 1:
                    { $('#starid1').addClass('classStar1'); }
                    break;
                case 2:
                    {
                        $('#starid1').addClass('classStar1');
                        $('#starid2').addClass('classStar1');
                        break;
                    }
                case 3:
                    {
                        $('#starid1').addClass('classStar1');
                        $('#starid2').addClass('classStar1');
                        $('#starid3').addClass('classStar1');
                        break;
                    }
                case 4:
                    {
                        $('#starid1').addClass('classStar1');
                        $('#starid2').addClass('classStar1');
                        $('#starid3').addClass('classStar1');
                        $('#starid4').addClass('classStar1');
                        break;
                    }
                case 5:
                    {
                        $('#starid1').addClass('classStar1');
                        $('#starid2').addClass('classStar1');
                        $('#starid3').addClass('classStar1');
                        $('#starid4').addClass('classStar1');
                        $('#starid5').addClass('classStar1');
                        break;
                    }
            }

        }
    }

    //删除上架信息对话框
    function DeleteDialog() {
        //首先获取选中的上架信息的所有信息
        var checkdata = $("#View").datagrid("getSelections");//获取整行数据
        if (checkdata.length == 1) {
            var checkdata = $("#View").datagrid("getSelections")[0];//获取整行数据
            var postdata = {
                EvaID: checkdata.EvaID,//评价ID
                FormID: checkdata.FormID,//订单ID
                DishesID: checkdata.DishesID,//商品ID
                MerID: checkdata.MerID,//商户ID
                AccID: checkdata.AccID,//用户ID
                EvaTxt: checkdata.EvaTxt,//评价内容
                EvaTime: checkdata.EvaTime,//评价时间
                EvaStars: checkdata.EvaStars,//评价星级
                MerTxt: checkdata.MerTxt,//商户回复评价
                BZ: checkdata.BZ,//备注
            };
            //发送异步请求删除数据
            $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + "</font>该条评价吗？", function (ok) {
                if (ok) {
                    $.post("/Order_Eva/UpdateOrder_Eva?Tag=" + 3, postdata, function (data) {
                        if (data == "1") {
                            $.messager.alert("友情提示", "删除成功");
                            initTable(Mer);
                        }
                        else {
                            $.messager.alert("友情提示", "删除失败:" + data);
                        }
                    });
                }
            });
        }
        else {
            $.messager.alert("友情提示", "每次只能删除一行数据，你已经选择了<font color='red' size='6'>" + checkdata.length + "</font>行");
        }
    }

    //保存
    function submitForm() {
        //首先判断前台的验证是否通过
        var valid = $('#editController').form('validate');

        if (valid == false) {
            return false;

        }
        var postdata = {
            EvaID: EvaID,
            FormID: $("#Form").textbox('getValue'),
            DishesID: DishesID,
            MerID: Mer,
            AccID: AccID,
            EvaTxt: $("#EvaTxt").textbox('getValue'),
            EvaTime: $("#EvaTime").textbox('getValue'),
            EvaStars: EvaStars,
            MerTxt: $("#MerTxt").textbox('getValue'),
            //DishesPic: filePath,
            BZ: $("#BZ").textbox('getValue'),
            EvaState: 1
        };

        var Tag = 2;
        //使用异步实现修改用户信息
        $.post("/Order_Eva/UpdateOrder_Eva?Tag=" + Tag, postdata, function (date) {
            if (date == "1") {
                $("#editDialog").dialog('close');
                $("#View").datagrid('reload');
            }
            else {
                $.messager.alert("友情提示", "回复评价失败，请检查");
            }
        });
    }

</script>
<style>
    .classStar {
        width: 21px;
        height: 21px;
        display: inline-block;
        margin: 3px 5px 0px;
        background-image: url(/Content/img/星星.png);
    }

    .classStar1 {
        width: 21px;
        height: 21px;
        display: inline-block;
        margin: 3px 5px 2px;
        background-image: url(/Content/img/星星.png);
        background-position: -20px -20px;
    }
</style>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body style="padding: 0px">
    <div style="padding: 5px; background-color: #F4F4F4">
        <div>
            <a>商户：</a>
            <input id="SearchMer" class="easyui-combogrid" style="width: 120px" />
        </div>
    </div>
    <div>
        <table id="View"></table>
    </div>
    <div id="tb1" style="background-color: #F4F4F4">
        <div>
            <div style="margin-bottom: 5px">
                <a href="#" class="easyui-linkbutton" iconcls="icon-more" id="btndetail" onclick="DetailDialog()" plain="true">明细</a>
                <a href="#" class="easyui-linkbutton" iconcls="icon-cancel" id="btndell" onclick="DeleteDialog()" plain="true">删除</a>
            </div>
        </div>
        <div style="margin-left: 5px;">
            <a>商品名称：</a>
            <input id="SearchDishes" class="easyui-textbox" style="width: 120px" />
            <a>订单号：</a>
            <input id="FormID" class="easyui-textbox" style="width: 120px" />
            <a>星级：</a>
            <select id="Star" class="easyui-combobox" style="width: 120px;">
                <option value="0"></option>
                <option value="1">1星</option>
                <option value="2">2星</option>
                <option value="3">3星</option>
                <option value="4">4星</option>
                <option value="5">5星</option>
                <option value="">全部</option>
            </select>
            <a id="SearchBtn" href="#" class="easyui-linkbutton" onclick="SearchDishes()" data-options="iconCls:'icon-search'">检索</a>
        </div>
    </div>
    <div id="editDialog" class="easyui-dialog" style="width: 600px; padding: 10px; padding: fixed; top: 5px;" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="editController" method="post" novalidate="novalidate">
            <table cellpadding="10" width="500" id="tbledit">
                <tr>
                    <td class="userinfo-td-l">商户名称：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-textbox" type="text" readonly="true" id="DishesNmae" name="DishesNmae" />
                    </td>
                    <td width="50"></td>
                    <td class="userinfo-td-l">订单号：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-textbox" type="text" readonly="true" id="Form" name="Form" />
                </tr>
                <tr></tr>
                <tr>
                    <td class="userinfo-td-l">评价用户：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-textbox" type="text" readonly="true" id="AccName" name="AccName" /></td>
                    <td width="50"></td>
                    <td class="userinfo-td-l">评价时间：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-textbox" type="text" readonly="true" id="EvaTime" name="EvaTime" />
                    </td>
                </tr>
                <tr></tr>
                <tr>
                    <td class="userinfo-td-l">评价星级：</td>
                    <td class="userinfo-td-r">
                        <p>
                            <i id="starid1"></i>
                            <i id="starid2"></i>
                            <i id="starid3"></i>
                            <i id="starid4"></i>
                            <i id="starid5"></i>
                        </p>
                    </td>
                </tr>
                <tr>
                    <td class="userinfo-td-l">评价内容：</td>
                    <td class="userinfo-td-r" colspan="4">
                        <input class="easyui-textbox" style="width: 420px; height: 50px" data-options="multiline:true" readonly="true" type="text" id="EvaTxt" name="EvaTxt" /></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td class="userinfo-td-l">评价回复：</td>
                    <td class="userinfo-td-r" colspan="4">
                        <input class="easyui-textbox" style="width: 420px; height: 50px" data-options="multiline:true" type="text" id="MerTxt" name="MerTxt" /></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td class="userinfo-td-l">备注：</td>
                    <td class="userinfo-td-r" colspan="4">
                        <input class="easyui-textbox" data-options="multiline:true" style="width: 420px; height: 50px" type="text" id="BZ" name="BZ" /></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </table>
            <br />
            <div align="centens">
                <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="submitForm()">回复</a>
            </div>
        </form>
    </div>
</body>
</html>
